goog.provide('czk.ui.tab.Tabs');

goog.require('goog.dom');
goog.require('goog.dom.TagName');

goog.require('czk.ui.ZKComponent');

/**
 * @constructor
 * @extends {czk.ui.ZKComponent}
 */
czk.ui.tab.Tabs = function() {
  goog.base(this);
};
goog.inherits(czk.ui.tab.Tabs, czk.ui.ZKComponent);

czk.ui.tab.Tabs.prototype.selectIndex = null;

czk.ui.tab.Tabs.prototype.createDom = function() {
  var dh = this.getDomHelper();
  var el = dh.createDom(goog.dom.TagName.DIV, {
    'className': 'tab-navigation'
  });

  this.setElementInternal(el);

  this.getParent().tabs = this;
};

czk.ui.tab.Tabs.prototype.enterDocument = function() {
  goog.base(this, 'enterDocument');
  var dh = this.getDomHelper();
  var el = this.getElement();
  var clear = dh.createDom(goog.dom.TagName.DIV, {
    className: 'clear'
  });
  goog.dom.insertChildAt(el, clear);
};

czk.ui.tab.Tabs.prototype.select = function(e) {
  this.selectIndex = this.indexOfChild(e);
  this.dispatchEvent(czk.ui.tab.Tabbox.EventType.SELECT);
  this.forEachChild(function(child, i) {
    child.setSel(this.selectIndex == i);
  }, this);
};

czk.ui.tab.Tabs.create = function() {
  return new czk.ui.tab.Tabs();
};
